package com.college.collegeinfomanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.college.collegeinfomanage.dto.FacultyDTO;
import com.college.collegeinfomanage.entity.Faculty;
import com.college.collegeinfomanage.service.FacultyService;
import com.college.collegeinfomanage.util.Result;
import com.college.collegeinfomanage.vo.FacultyListVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RestController
@RequestMapping("/faculty")
public class FacultyController {

    @Resource
    private FacultyService facultyService;

    @PostMapping("/add")
    public Result add(@RequestBody Faculty faculty){
        boolean save = facultyService.save(faculty);
        return save ? Result.success("添加成功") : Result.fail("添加失败");
    }

    @GetMapping("/list")
    public Result list(FacultyDTO facultyDTO){
        IPage<FacultyListVO> page = facultyService.getPage(facultyDTO);
        return Result.success(page);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Faculty faculty){
        boolean update = facultyService.updateById(faculty);
        return update ? Result.success("修改成功") : Result.fail("修改失败");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        boolean remove = facultyService.removeById(id);
        return remove ? Result.success("删除成功") : Result.fail("删除失败");
    }
}
